﻿rc = LibStub("AceAddon-3.0"):NewAddon("roguecraft", "AceHook-3.0", "AceConsole-3.0", "AceTimer-3.0")
local def = {
	profile = {
		name = UnitName"player",
		class = nil,
		race = nil,
		sex = nil,
		level = 1,
		stats = {
			str = 10,
			dex = 10,
			con = 10,
			int = 10,
			wil = 10,
			cha = 10,
			},
		gold = 0,
		exp = 0,
		x-coord = 0,
		y-coord = 0,
		inventory = { },
		sanity = 100,
		board-x = 200,
		board-y = 120,
		}
	}
	
local char = { 
	mdam = 0,
	speed = 0,
	blunt_resist = 0,
	sharp_resist = 0,
	energy_resist = 0,
	hit = 0,
	xpmod = 0,
	}

function rc:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("rogue-DB", def)
	self.db.RegisterCallback(self, "OnProfileChanged", "UpdateConfig")
	self.db.RegisterCallback(self, "OnProfileCopied", "UpdateConfig")
	self.db.RegisterCallback(self, "OnProfileReset", "UpdateConfig")
	
	for k, v in pairs(self.db.profile) do
		char[k] = v
	end
end

function rc:OnEnable()
	if not self.f then
		local w = char.board-x / 2
		local h = char.board-y / 2
		
		self.f = CreateFrame("Frame", nil, UIParent)
		self.f:SetWidth(char.board-x * 12)
		self.f:SetHeight(char.board-y * 12)
		self.f:SetBackdrop({bgFile = [[Interface\ChatFrame\ChatFrameBackground]], insets = {top = -2, left = -2, bottom = -2, right = -2}})
		self.f:SetBackdropColor(0, 0, 0, 0.6)
		
		for i = -w, w do
			for j = -h, h do
				self.f[i][j] = CreateFontString(nil, "OVERLAY")
				self.f[i][j]:SetWidth(12)
				self.f[i][j]:SetHeight(12)
				if i == -w and j == -h then
					self.f[i][j]:SetPoint("TOPLEFT", self.f)
				else
					if ((j-1)<-h) then 
						self.f[i][j]:SetPoint("TOPLEFT", self.f[i-1][j], "TOPRIGHT")
					else
						self.f[i][j]:SetPoint("TOPLEFT", self.f[i][j-1], "BOTTOMLEFT")
					end
				end
			end
		end
	else
		self.f:Show()
	end
end

function rc:OnDisable()
  -- Unhook, Unregister Events, Hide frames that you created.
  -- You would probably only use an OnDisable if you want to 
  -- build a "standby" mode, or be able to toggle modules on/off.
end
